﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace AirDrive.Companion
{
    class Program
    {
        private static EventWaitHandle s_event;
        [STAThread]
        static void Main(string[] args)
        {
            bool created;
            s_event = new EventWaitHandle(false, EventResetMode.ManualReset, "Mara.Apps.AirDrive.Companion", out created);
            if (created)
            {
                string fullPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft\\Windows\\Start Menu\\Programs\\Startup\\StartAirDriveCompanion.bat");

                if (!File.Exists(fullPath))
                {
                    string[] mystrings = new string[] { @"@echo off 
if exist ""%appdata%\Microsoft\Windows\Start Menu\Programs\Mara apps\AirDrive Companion.appref-ms"" (
""%appdata%\Microsoft\Windows\Start Menu\Programs\Mara apps\AirDrive Companion.appref-ms""
) else (
(goto) 2>nul & del ""%~f0""
)"};

                    //Expands the %appdata% path and writes the file to the Startup folder
                    File.WriteAllLines(Environment.ExpandEnvironmentVariables(fullPath), mystrings);
                }

                SystemTrayController sysTray = new SystemTrayController();
                sysTray.Show();

                Application.Run();
            }
        }
    }
}
